/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cart;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.*;
import java.text.*;

/**
 *
 * @author Sam WONG
 */
public class LatestItem extends HttpServlet {
    private int[] moviename;
    
    public LatestItem(){
        int[] moviename = new int[3];
    }
    public void setMovieName(int index, int integer){
        moviename[index] = integer;
    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
         try{
            Class.forName("com.mysql.jdbc.Driver");
        }catch(Exception E){
        }
        
        try {
               Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/eshop","root","");
               Statement Stmt = Conn.createStatement();        
               String sqlstatement = "SELECT * FROM movie_information ORDER BY release_date DESC LIMIT 3";
               ResultSet rs  = Stmt.executeQuery(sqlstatement);
               for (int i=0;i<3;i++){
                  rs.next();
                  this.setMovieName(i, rs.getInt("movie_id"));
               }
        }catch(SQLException E){
        }
    }
}
